#ifndef DESKTIDY_H
#define DESKTIDY_H

class DeskTidy;

#include "common.h"
#include "resource.h"
#include "DeskTidyWnd.h"
#include "Settings.h"
#include "WMCallback.h"

class DeskTidy : public CassiopeiaComponent
{
public:
	~DeskTidy();
	CCState Activate();
	CCState Deactivate();

	static DeskTidy* CreateInstance(HINSTANCE hInstance);
private:
	struct ItemLocation
	{
		int Index;
		POINT Location;
	};

	enum PageState
	{
		None,
		Error,
		LastPage,
		FirstPage
	};

	DeskTidy(HINSTANCE hInstance);
	
	map<int, list<ItemLocation>> GetItemPositions(HWND deskTidyHWnd, int deskTidyWndID);
	PageState OpenCloseDeskTidyWnd(DeskTidyWnd* deskTidyWnd, bool active, int page);
	void SetItemPositionBelowGroupWnd(HWND hWnd, HWND desktopHWnd, RECT desktopBounds, int itemIndex, POINT itemPosition, RECT itemBounds, SIZE gridSize, int *counterX, int *counterY);
	void LoadData(HINSTANCE hInstance);
	void SaveData();
	void RefreshItemLists();
	void RefreshItemPositions();
	void EmptyDesktop();
	void Refresh();

	map<int, DeskTidyWnd*> deskTidyWnds;
	map<int, set<tstring, TStringSortTemplate>> itemLists;
	map<int, set<tstring, TStringSortTemplate>> extensionLists;
	list<int> freeIDPool;
	tstring desktopPath;
	tstring publicDesktopPath;
	DesktopHelper* desktopHelper;
	WMCallback* wmCallback;
	HINSTANCE hInstance;
	int idCounter;


	static DeskTidy* instance;

	static LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
	static INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
	static void deskTidyWnds_SwitchToNextPage(DeskTidyWnd* sender);
	static void deskTidyWnds_SwitchToPrevPage(DeskTidyWnd* sender);
	static void OnActiveChanged(DeskTidyWnd* sender);
	static void OnRefresh(DeskTidyWnd* sender);
	static void OnNewClicked(DeskTidyWnd* sender);
	static void OnRemoveClicked(DeskTidyWnd* sender);
	static void OnPropertiesClicked(DeskTidyWnd* sender);
};

#endif
